package com.jz.cash.client.service.impl;

import com.jz.cash.client.entity.TableType;
import com.jz.cash.client.service.TableTypeService;
import com.jz.cash.client.vo.TableCategoryVo;
import com.stip.mybatis.generator.plugin.BaseExample;
import com.stip.mybatis.generator.plugin.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class TableTypeServiceImpl extends BaseService<TableType, BaseExample, Long> implements TableTypeService {

    @Override
    public List<TableCategoryVo> getCategoryListByMerchantId(Long merchantId) {
        BaseExample example = new BaseExample();

        example.createCriteria().addCriterion("merchant_id=", merchantId);
        example.setOrderByClause(" sorted asc");

        List<TableType> tableTypes = selectByExample(example);

        if (!CollectionUtils.isEmpty(tableTypes)) {
            return tableTypes.stream().map(f -> {
                TableCategoryVo vo = new TableCategoryVo();
                vo.setId(f.getId());
                vo.setName(f.getName());
                return vo;
            }).collect(Collectors.toList());
        }
        return null;
    }
}